﻿using StockHelper.Scripts;
using StockHelper.Scripts.Stock;
using StockHelper.Scripts.Types;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StockHelper
{
    public partial class AddStock : Form
    {

        public AddStock()
        {
            InitializeComponent();

        }

        private void AddStockBtn_Click(object sender, EventArgs e)
        {
            string url = this.apiUrl.Text.Trim();
            if (string.IsNullOrEmpty(url)) {
                MessageBox.Show("请填写接口,是一个链接地址,可以直接浏览器打开");
                return;
            }

            if (Config.Get("stockList", new ArrayList()).IndexOf(url) > -1)
            {
                MessageBox.Show("已经添加该接口");
                return;
            }

            StockCtrl.Add(url);
            if(!Mine.e.IsDisposed)
            Mine.e.AddStockOnList(url);
            StockCtrl.GetNewData();
            this.Dispose();
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IDataObject iData = Clipboard.GetDataObject();
            if (iData.GetDataPresent(DataFormats.Text))
                this.apiUrl.Text = (string)iData.GetData(DataFormats.Text);
        }
    }
}
